import fs from "fs";
import csvParser from "csv-parser";
import { PrismaClient } from "@prisma/client";
const prisma = new PrismaClient();

const results = [];
fs.createReadStream("./resultcsv-fanhua.csv")
  .pipe(csvParser())
  .on("data", (row) => {
    results.push(row);
  })
  .on("end", async () => {
    for (let index = 0; index < results.length; index++) {
      const dataset = await prisma.dataset.findUnique({
        where: {
          name: `test${index + 1}`,
        },
      });
      await prisma.testResult.create({
        data: {
          datasetId: dataset.id,
          indicator1: parseFloat(results[index]["mAP_0.5"]),
          indicator2: parseFloat(results[index]["mAP_50_95"]),
        },
      });
    }
  });
